package com.tool;

import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

import javax.sql.*;

import com.alibaba.druid.pool.DruidDataSourceFactory;
//构建连接池
public class MysqlTool {
    public static DataSource DATA_SOURCE = null;
    private static synchronized DataSource dataSource()throws Exception{
        if (DATA_SOURCE == null){
            Properties properties = new Properties();
            InputStream druidInputStream = MysqlTool.class.getClassLoader().getResourceAsStream("dataSource");
            properties.load(druidInputStream);
            DATA_SOURCE = DruidDataSourceFactory.createDataSource(properties);
        }
        return DATA_SOURCE;
    }
    //获取连接
    public static Connection connection()throws Exception{
        return dataSource().getConnection();
    }

}

